package handle

import (
	"context"
	"fmt"
	"net/http"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
)

func NewRedirect() Redirect {
	return Redirect{}
}

type Redirect struct {
}

func (r Redirect) InitRoute(server *server.Hertz) {
	p := server.Group("/trans")
	p.GET("/redirect", r.Redirect())
	p.GET("/exec", r.Exec())
	p.GET("/serveHttpc", r.ServeHTTPC())
	p.GET("/default", r.Default())
}
func (r Redirect) Redirect() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		ctx.Redirect(http.StatusMovedPermanently, []byte("/trans/exec"))
	}
}
func (r Redirect) ServeHTTPC() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		fmt.Println("ServeHTTPC")
	}
}
func (r Redirect) Exec() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		fmt.Println("Exec")
	}
}
func (r Redirect) Default() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		fmt.Println("Default")
	}
}
